from flask import Flask,current_app
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
db = SQLAlchemy()

migrate = Migrate()
#单独封装函数
#工厂函数（进行项目初始化加载）
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile('setting.py')

    #注册数据库
    db.init_app(app)

    #注册迁移对象
    migrate.init_app(app,db)

    #引入数据模型
    #每个蓝图下的模型都要导入
    from app.blog import moudels
    from app.admin import moudels
    #  注册蓝图到app
    from app.blog import views as blog_views
    app.register_blueprint(blog_views.bp)
    return app